{
  "name": "Case 1 - Home Loan Credit Appraisal",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Home Loan Application",
        "formDescription": "Submit your Home Loan Application",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Applicant Name",
              "requiredField": true
            },
            {
              "fieldLabel": "Email id",
              "fieldType": "email",
              "requiredField": true
            },
            {
              "fieldLabel": "Phone number"
            },
            {
              "fieldLabel": "Applicant Financial Dossier",
              "fieldType": "file",
              "acceptFileTypes": ".pdf",
              "requiredField": true
            }
          ]
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [0, 0],
      "name": "On form submission"
    },

    {
      "parameters": {
        "inputDataFieldName": "Applicant Financial Dossier",
        "name": "={{ $json['Applicant Name'] }}_HomeLoan",
        "folderId": "REPLACE_WITH_APPLICANT_DOCUMENTS_FOLDER_ID"
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [220, 0],
      "name": "Upload file"
    },

    {
      "parameters": {
        "operation": "download",
        "fileId": "={{ $json.id }}"
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [420, 0],
      "name": "Download file"
    },

    {
      "parameters": {
        "operation": "pdf"
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [620, 0],
      "name": "Extract from File"
    },

    {
      "parameters": {
        "operation": "download",
        "fileId": "REPLACE_WITH_CREDIT_POLICY_PDF_FILE_ID"
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [820, 0],
      "name": "Download Credit Policy"
    },

    {
      "parameters": {
        "operation": "pdf"
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [1020, 0],
      "name": "Extract Credit Policy"
    },

    {
      "parameters": {
        "promptType": "define",
        "text": "=Applicant Financial Dossier:\n{{ $('Extract from File').item.json.text }}\n\nBank Credit Policy:\n{{ $('Extract Credit Policy').item.json.text }}",
        "options": {
          "systemMessage": "You are a Senior Credit Risk Manager at a retail bank. Perform a structured home loan credit appraisal strictly as per the provided Bank Credit Policy.\n\nYou MUST output ONLY valid JSON with the following 33 keys:\n\nApplication ID, Applicant Name, Loan Type, Requested Loan Amount (₹), Loan Tenure (Years), Property Location, Application Date, Employment Type, Employer / Business Name, Total Work Experience (Years), Years with Current Employer, Net Monthly Income (₹), Income Trend, Existing Monthly Obligations (₹), Proposed Home Loan EMI (₹), Total Monthly Obligations (₹), Post-loan FOIR (%), FOIR Status, Property Agreement Value (₹), Assessed Market Value (₹), Property Value Considered (₹), Loan-to-Value (LTV %), LTV Status, Credit Bureau Score, DPD History, Recent Credit Enquiries, Overall Credit Behaviour, Stress Test Result, Overall Risk Grade, Key Credit Risks Identified, Key Mitigating Factors, Overall Credit Decision, Credit Manager Justification\n\nNo text outside JSON."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [220, 260],
      "name": "AI Agent"
    },

    {
      "parameters": {
        "model": "gpt-4.1-mini"
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [0, 420],
      "name": "OpenAI Chat Model"
    },

    {
      "parameters": {
        "operation": "append",
        "documentId": "REPLACE_WITH_GOOGLE_SHEET_ID",
        "sheetName": "Home Loan – Credit Appraisal Register"
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [420, 460],
      "name": "Append row"
    },

    {
      "parameters": {
        "sendTo": "={{ $('On form submission').item.json['Email id'] }}",
        "subject": "Home Loan Application – Initial Credit Review",
        "message": "Dear {{ $('On form submission').item.json['Applicant Name'] }},\n\nThank you for submitting your home loan application. Your application has been reviewed as per our internal credit policy. We will reach out if further information is required.\n\nRegards,\nCredit Team"
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [420, 260],
      "name": "Send Email"
    }
  ],

  "connections": {
    "On form submission": { "main": [[{ "node": "Upload file" }]] },
    "Upload file": { "main": [[{ "node": "Download file" }]] },
    "Download file": { "main": [[{ "node": "Extract from File" }]] },
    "Extract from File": { "main": [[{ "node": "Download Credit Policy" }]] },
    "Download Credit Policy": { "main": [[{ "node": "Extract Credit Policy" }]] },
    "Extract Credit Policy": { "main": [[{ "node": "AI Agent" }]] },
    "OpenAI Chat Model": { "ai_languageModel": [[{ "node": "AI Agent" }]] },
    "AI Agent": { "main": [[{ "node": "Send Email" }]] },
    "Append row": { "ai_tool": [[{ "node": "AI Agent" }]] }
  },

  "active": false
}
